<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>主要内容区main</title>
<link href="../include/css/css.css" type="text/css" rel="stylesheet" />
<link href="../include/css/main.css" type="text/css" rel="stylesheet" />
<link rel="shortcut icon" href="../include/images/main/favicon.ico" />
<style>
body{overflow-x:hidden; background:#f2f0f5; padding:15px 0px 10px 5px;}
#searchmain{ font-size:12px;}
#search{ font-size:12px; background:#548fc9; margin:10px 10px 0 0; display:inline; width:100%; color:#FFF; float:left}
#search form span{height:40px; line-height:40px; padding:0 0px 0 10px; float:left;}
#search form input.text-word{height:24px; line-height:24px; width:180px; margin:8px 0 6px 0; padding:0 0px 0 10px; float:left; border:1px solid #FFF;}
#search form input.text-but{height:24px; line-height:24px; width:55px; background:url(../include/images/main/list_input.jpg) no-repeat left top; border:none; cursor:pointer; font-family:"Microsoft YaHei","Tahoma","Arial",'宋体'; color:#666; float:left; margin:8px 0 0 6px; display:inline;}
#search a.add{ background:url(../include/images/main/add.jpg) no-repeat -3px 7px #548fc9; padding:0 10px 0 26px; height:40px; line-height:40px; font-size:14px; font-weight:bold; color:#FFF; float:right}
#search a:hover.add{ text-decoration:underline; color:#d2e9ff;}
#main-tab{ border:1px solid #eaeaea; background:#FFF; font-size:12px;}
#main-tab th{ font-size:12px; background:url(../include/images/main/list_bg.jpg) repeat-x; height:32px; line-height:32px;}
#main-tab td{ font-size:12px; line-height:40px;}
#main-tab td a{ font-size:12px; color:#548fc9;}
#main-tab td a:hover{color:#565656; text-decoration:underline;}
.bordertop{ border-top:1px solid #ebebeb}
.borderright{ border-right:1px solid #ebebeb}
.borderbottom{ border-bottom:1px solid #ebebeb}
.borderleft{ border-left:1px solid #ebebeb}
.gray{ color:#dbdbdb;}
td.fenye{ padding:10px 0 0 0; text-align:right;}
.bggray{ background:#f9f9f9}
</style>
</head>
<body>
<!--main_top-->
<table width="99%" border="0" cellspacing="0" cellpadding="0" id="searchmain">
  <tr>
    <td width="99%" align="left" valign="top">您的位置：订单管理</td>
  </tr>
  <?php 
        //error_reporting(E_ALL & ~E_NOTICE);    
        //$_GET['typeid'] = empty($_GET['typeid']) ? '' : $_GET['typeid'];
        $_GET['id'] = empty($_GET['id']) ? '' : $_GET['id'];
        $_GET['status'] = empty($_GET['status']) ? '' : $_GET['status'];
        $wherelist = array();
        $where = '';
        $urllist = array();
        $url = '';
        
    ?>
  <tr>
    <td align="left" valign="top">
    <table width="100%" border="0" cellspacing="0" cellpadding="0" id="search">
  		<tr>
   		 <td width="90%" align="left" valign="middle">
	         <form action="indexnew.php">
                <!--<span>商品类别ID:</span>
                <input type="text" name="typeid" value="<?php echo $_GET['typeid']; ?>" size='3' class="text-word">-->
                <span>订单号:</span>
                <input type="text" name="id" value="<?php echo $_GET['id']; ?>" size='3' class="text-word">
                <span>状态:</span>
                    <select name='status' class="text-word" class="text-but" style="margin:10px 0px">
                        <option value=''>-请选择-</option>
                        <option value='1' <?php echo $_GET['status']=='1' ? 'selected' : '';?> >新订单</option>
                        <option value='2' <?php echo $_GET['status']=='2' ? 'selected' : '';?> >已发货</option>
                        <option value='3' <?php echo $_GET['status']=='3' ? 'selected' : '';?> >已收货</option>
                    </select>
                <input type="submit" value="查询">
               
	         </form>
         </td>
  		  <td width="10%" align="center" valign="middle" style="text-align:right; width:150px;"><a href="edit.php" target="mainFrame" onFocus="this.blur()" class="add">修改订单</a></td>
  		</tr>
	</table>
    </td>
  </tr>
  <tr>
    <td align="left" valign="top">
    
    <table width="100%" border="0" cellspacing="0" cellpadding="0" id="main-tab">
      <tr>
        <th align="center" valign="middle" class="borderright">订单号</th>
        <th align="center" valign="middle" class="borderright">会员ID号</th>
        <th align="center" valign="middle" class="borderright">联系人</th>
        <th align="center" valign="middle" class="borderright">地址</th>
        <th align="center" valign="middle" class="borderright">邮编</th>
        <th align="center" valign="middle" class="borderright">电话</th>
        <th align="center" valign="middle" class="borderright">购买时间</th>
        <th align="center" valign="middle" class="borderright">总金额</th>
        <th align="center" valign="middle" class="borderright">状态</th>
        <!--<th align="center" valign="middle" class="borderright">商品名</th>
        <th align="center" valign="middle" class="borderright">单价</th>
        <th align="center" valign="middle" class="borderright">数量</th>-->
        <th align="center" valign="middle">操作</th>
      </tr>
     <?php
			//六脉神剑	
			include("../../public/dbconfig.php");
			$link = @mysqli_connect(HOST,USER,PASS,DBNAME) or die("数据库连接失败");
			mysqli_set_charset($link,"utf8");
			//封装搜索条件
            //1 设置数组接受搜索条件
            // var_dump($_GET);die;
            //2 接收搜索条件
            //var_dump(isset($_GET['typeid']));
            
            // if(isset($_GET['typeid'])){
                // $wherelist = " path like '%0,{$_GET['typeid']}%'";
                // $urllist[] = "typeid={$_GET['typeid']}";
            // }
                $time = time()-86400;
                //echo time(),$time;
                $wherelist[] = " addtime>{$time}";
            if(!empty($_GET['id'])){
                $wherelist[] =" id = {$_GET['id']}";
                $urllist[] = "id={$_GET['id']}";
            }
            
            if(!empty($_GET['status'])){
                $wherelist[] =" status='{$_GET['status']}'";
                $urllist[] = "status={$_GET['status']}";
            }
            // print_r($wherelist);
            // echo count($wherelist);die;
            // print_r($urllist);die;
            // $url = empty($url) ? '' : $url;
            //判断搜索条件有效
            if(count($wherelist)>0){
                $where = " where ".implode(" and ",$wherelist);
                //select g.* from goods g,type t where g.typeid=t.id and path like '%0,9';
                $url = "&".implode("&",$urllist);
            }
            // echo $where;die;
            echo "<hr>";
            // $sql1 = "select id from type where .{$idlist}";
            // echo $sql1;
            // $result2 = mysqli_query($link,$sql1);
            //$id = mysqli_fetch_assoc($result2);
            //print_r($id);die;
            // echo $where."<br>",$url;die;
            $sql = "select * from orders ".$where;
            // echo $sql;
            // echo $sql;
            $result1 = mysqli_query($link,$sql);
            
            //封装搜索条件
            
            //实现分页
            //设置参数
            $page = empty($_GET['page']) ? 1 : $_GET['page'];
            $maxRow = 0;//共多少条
            $pageSize = 4;//页大小
            $maxPage = 0;//共多少页
            $maxRow = mysqli_num_rows($result1);
            // echo $maxRow;
            
            $maxPage = ceil($maxRow/$pageSize);
            
            if($page>$maxPage){
                $page = $maxPage;
            }
            if($page<1){
                $page = 1;
            }
            $limit = " limit ".($page-1)*$pageSize.",".$pageSize;
            
            // echo $sql;
            //实现分页
            $sql = "select * from orders".$where.$limit;
             // echo $sql;die;
            $arr = array("1"=>"新订单","2"=>"已发货","3"=>"已收货"); 
			$result = mysqli_query($link,$sql);
			while($row = mysqli_fetch_assoc($result)){
			date_default_timezone_set("PRC");
            $time = date('Y-m-d',$row['addtime']);
                
            
$str = <<<aa
        <tr class="bggray" onMouseOut="this.style.backgroundColor='#f9f9f9'" onMouseOver="this.style.backgroundColor='#edf5ff'">
        <td align="center" valign="middle" class="borderright borderbottom">{$row['id']}</td>
        <td align="center" valign="middle" class="borderright borderbottom">{$row['uid']}</td>
        <td align="center" valign="middle" class="borderright borderbottom">{$row['linkman']}</td>
        <td align="center" valign="middle" class="borderright borderbottom">{$row['address']}</td>
        <td align="center" valign="middle" class="borderright borderbottom">{$row['code']}</td>
        <td align="center" valign="middle" class="borderright borderbottom">{$row['phone']}</td>
        <td align="center" valign="middle" class="borderright borderbottom">{$time}</td>
        <td align="center" valign="middle" class="borderright borderbottom">{$row['total']}</td>
        <td align="center" valign="middle" class="borderright borderbottom">{$arr[$row['status']]}</td>
        <td align="center" valign="middle" class="borderbottom">
            <a href="edit.php?id={$row['id']}" target="mainFrame" onFocus="this.blur()" class="add">编辑</a>
            <span class="gray">&nbsp;|&nbsp;</span>
            <a href="index1.php?id={$row['id']}" target="mainFrame" onFocus="this.blur()" class="add">订单详情</a>
        </td>
      </tr>
aa;
        echo $str;
            }
?>
      
    </table></td>
    </tr>
  <tr>
    <td align="left" valign="top" class="fenye"><?php echo mysqli_num_rows($result1);?>条数据<?php echo $page;?>/<?php echo $maxPage;?>页&nbsp;&nbsp;
    <a href="indexnew.php?page=1<?php echo $url;?>" target="mainFrame" onFocus="this.blur()">首页</a>&nbsp;&nbsp;
    <a href="indexnew.php?page=<?php echo ($page-1),$url; ?>" target="mainFrame" onFocus="this.blur()">上一页</a>&nbsp;&nbsp;
    <a href="indexnew.php?page=<?php echo ($page+1),$url; ?>" target="mainFrame" onFocus="this.blur()">下一页</a>&nbsp;&nbsp;
    <a href="indexnew.php?page=<?php echo $maxPage,$url; ?>" target="mainFrame" onFocus="this.blur()">尾页</a></td>
  </tr>
    <?php
        mysqli_close($link);
		mysqli_free_result($result1);
		mysqli_free_result($result);
    ?>
</table>
</body>
</html>